//
//  CSGuideConnectController.m
//  CreateWithSuper
//
//  Created by chenjunbo on 2024/5/27.
//  Copyright © 2024 CS. All rights reserved.
//

#import "CSGuideConnectController.h"
#import "CSGuidePopView.h"
#import "CSLoadController.h"
//#import "ADModule.h"
#import "CSNetworkHelper.h"

@interface CSGuideConnectController ()

@property (weak, nonatomic) IBOutlet UIImageView *connectStatusImgView;
@property (nonatomic, strong) NSTimer *conTimer;
@property (nonatomic, strong) NSTimer *showAdTimer;

@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityView;
@property (weak, nonatomic) IBOutlet UIView *activityMainView;

@property (nonatomic, assign) NSInteger loadTime;
@property (weak, nonatomic) IBOutlet UISwitch *onSwitch;


@end

@implementation CSGuideConnectController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.loadTime = 0;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        CSGuidePopView *popView = [[CSGuidePopView alloc]init];
        popView.modalPresentationStyle = UIModalPresentationOverFullScreen;
        [self presentViewController:popView animated:NO completion:nil];
        
        UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
        view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
        [[UIApplication sharedApplication].keyWindow addSubview:view];
        
        popView.leftBlock = ^{
            
            [view removeFromSuperview];
            
            CSGuidePopView *popView = [[CSGuidePopView alloc]init];
            popView.topStr = @"To speed up the network,click the \nAllow";
            popView.bottomStr = @"With this , you can: \n1 . Quickly generate AI paintings\n2 . Open unlimited AI painting";
            popView.modalPresentationStyle = UIModalPresentationOverFullScreen;
            [self presentViewController:popView animated:NO completion:nil];
            
            UIView *view1 = [[UIView alloc] initWithFrame:self.view.bounds];
            view1.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
            [[UIApplication sharedApplication].keyWindow addSubview:view1];
            
            popView.leftBlock = ^{
                [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"FirstInGuideConnect"];
                [view1 removeFromSuperview];
                CSLoadController *loadVC = [[CSLoadController alloc]init];
                [[CSNetworkHelper standardInstance]requestConfiguration];
                [UIApplication sharedApplication].keyWindow.rootViewController = loadVC;
            };
            
            popView.rightBlock = ^{
                [view1 removeFromSuperview];
                [self connectAction];
            };
            
        };
        
        popView.rightBlock = ^{
            [view removeFromSuperview];
            [self connectAction];
        };

    });
    
}

- (void)connectAction{


}

- (IBAction)switchChanged:(UISwitch *)sender {
    
    NSLog(@"%d",sender.on);
    
    if (sender.on){
        [self connectAction];
    }

}

- (IBAction)start:(UIButton *)sender {
    CSLoadController *loadVC = [[CSLoadController alloc]init];
    [[CSNetworkHelper standardInstance]requestConfiguration];
    [UIApplication sharedApplication].keyWindow.rootViewController = loadVC;
}

@end
